
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SubsistemaPaciente.programaMedico;

import Profesionales.DialogoInfoProfesionalExterno;
import SubsistemaPaciente.DialogoInfoPaciente;
import SubsistemaPaciente.Paciente;
import SubsitemaAgenda.DialogoAgregarCita;
import Usuario.DialogoInfoUsuarioProfesional;
import clienteSandraParada.Login;
import clienteSandraParada.Mensajeria;
import java.awt.Color;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.l2fprod.common.swing.renderer.DefaultCellRenderer;
import java.awt.Desktop;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.PrintService;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import org.jpedal.PdfDecoder;
import service.CodigosPrestaciones;
import service.ProgramaDipreca;

/**
 *
 * @author Rodrigo
 */
public class DialogoInfoProgramaMedicoDipreca extends java.awt.Dialog implements Printable {

    private ProgramaMedicoDipreca programa;
    private boolean dispose = false;
    private String numero;

    public DialogoInfoProgramaMedicoDipreca(java.awt.Frame parent, boolean modal, ProgramaMedicoDipreca programa) {
        super(parent, modal);
        this.programa = programa;
        initComponents();
        System.out.println(this.campoMensajeria.getX() + " " + this.campoMensajeria.getY());
        cargarCodigos();
        cargarEstablecimiento();
        campoPrestacion.setEnabled(false);
        campoCantidadFocusLost();
        campoDineroFocusLost();
        setIconImage(new ImageIcon(getClass().getResource("/GUI/Img/logo2.png")).getImage());
        DefaultTableCellRenderer tcr = new DefaultCellRenderer();
        tcr.setHorizontalAlignment(SwingConstants.CENTER);
        contenedorPrestaciones.getColumnModel().getColumn(1).setCellRenderer(tcr);
        contenedorPrestaciones.getColumnModel().getColumn(2).setCellRenderer(tcr);
        contenedorPrestaciones.getColumnModel().getColumn(3).setCellRenderer(tcr);
        contenedorPrestaciones.getColumnModel().getColumn(4).setCellRenderer(tcr);
        contenedorPrestaciones.getColumnModel().getColumn(5).setCellRenderer(tcr);
        rutFocusLost();
        numeroDiasFocusLost();
        campoFechaDesde.setDate(new Date());
        ocultarColumnaID();
    }

    public String getNumero() {
        return numero;
    }

    public JTable getTablaContenedoraPrestaciones() {
        return tablaContenedoraPrestaciones;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        DialogoVer = new javax.swing.JDialog();
        jPanel6 = new javax.swing.JPanel();
        jLabel27 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        etiquetaNumeroPrograma = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel40 = new javax.swing.JLabel();
        EtiquetaApellidoPaternoPaciente = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        etiquetaApellidoMaternoPaciente = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        etiquetaNombresPaciente = new javax.swing.JLabel();
        jLabel46 = new javax.swing.JLabel();
        etiquetaCalle = new javax.swing.JLabel();
        jLabel48 = new javax.swing.JLabel();
        etiquetaNumero = new javax.swing.JLabel();
        jLabel50 = new javax.swing.JLabel();
        etiquetaPoblacion = new javax.swing.JLabel();
        jLabel52 = new javax.swing.JLabel();
        etiquetaComuna = new javax.swing.JLabel();
        jLabel54 = new javax.swing.JLabel();
        etiquetaCiudad = new javax.swing.JLabel();
        etiquetaRutPaciente = new javax.swing.JLabel();
        jLabel57 = new javax.swing.JLabel();
        jSeparator6 = new javax.swing.JSeparator();
        etiquetaCMC = new javax.swing.JLabel();
        jLabel59 = new javax.swing.JLabel();
        etiquetaEdad = new javax.swing.JLabel();
        jLabel67 = new javax.swing.JLabel();
        etiquetaSexo = new javax.swing.JLabel();
        jLabel69 = new javax.swing.JLabel();
        jSeparator7 = new javax.swing.JSeparator();
        jLabel71 = new javax.swing.JLabel();
        jLabel73 = new javax.swing.JLabel();
        etiquetaTelefonoPaciente = new javax.swing.JLabel();
        etiquetaCelularPaciente = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel74 = new javax.swing.JLabel();
        etiquetaNombreEstablecimiento = new javax.swing.JLabel();
        jLabel80 = new javax.swing.JLabel();
        etiquetaFechaDesde = new javax.swing.JLabel();
        jLabel82 = new javax.swing.JLabel();
        jLabel84 = new javax.swing.JLabel();
        jLabel87 = new javax.swing.JLabel();
        jLabel102 = new javax.swing.JLabel();
        jSeparator10 = new javax.swing.JSeparator();
        jLabel103 = new javax.swing.JLabel();
        jSeparator11 = new javax.swing.JSeparator();
        etiquetaFechaHasta = new javax.swing.JLabel();
        jLabel107 = new javax.swing.JLabel();
        jLabel108 = new javax.swing.JLabel();
        jLabel109 = new javax.swing.JLabel();
        jLabel110 = new javax.swing.JLabel();
        jSeparator12 = new javax.swing.JSeparator();
        jSeparator13 = new javax.swing.JSeparator();
        jSeparator14 = new javax.swing.JSeparator();
        etiquetaNumeroDias = new javax.swing.JLabel();
        jLabel113 = new javax.swing.JLabel();
        etiquetaRutProfesional = new javax.swing.JLabel();
        etiquetaNombreProfesional = new javax.swing.JLabel();
        jLabel117 = new javax.swing.JLabel();
        jSeparator19 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        etiquetaDiagnostico1 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel88 = new javax.swing.JLabel();
        jSeparator5 = new javax.swing.JSeparator();
        etiquetaHistoriaClinica = new javax.swing.JLabel();
        jSeparator8 = new javax.swing.JSeparator();
        jSeparator22 = new javax.swing.JSeparator();
        jLabel17 = new javax.swing.JLabel();
        jSeparator17 = new javax.swing.JSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaContenedoraPrestaciones = new javax.swing.JTable();
        jLabel14 = new javax.swing.JLabel();
        etiquetaNumeroComplementario = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jSeparator15 = new javax.swing.JSeparator();
        jLabel116 = new javax.swing.JLabel();
        etiquetaNombreProfesionalExterno = new javax.swing.JLabel();
        jLabel114 = new javax.swing.JLabel();
        jLabel118 = new javax.swing.JLabel();
        jLabel119 = new javax.swing.JLabel();
        jLabel120 = new javax.swing.JLabel();
        jSeparator9 = new javax.swing.JSeparator();
        jSeparator16 = new javax.swing.JSeparator();
        jSeparator20 = new javax.swing.JSeparator();
        etiquetaRutProfesionalExterno = new javax.swing.JLabel();
        etiquetaEspecialidadExterno = new javax.swing.JLabel();
        etiquetaTelefonoExterno = new javax.swing.JLabel();
        etiquetaCelularExterno = new javax.swing.JLabel();
        jSeparator21 = new javax.swing.JSeparator();
        jLabel29 = new javax.swing.JLabel();
        etiquetaTotal = new javax.swing.JLabel();
        botonImprimir = new javax.swing.JButton();
        botonCancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        campoNumeroPrograma = new componentes.Numeros();
        jPanel2 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        campoRutPaciente = new componentes.Rut();
        jLabel35 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        campoApellidoPaternoPaciente = new javax.swing.JTextField();
        campoApellidoMaternoPaciente = new javax.swing.JTextField();
        campoNombresPaciente = new javax.swing.JTextField();
        campoEdadPaciente = new javax.swing.JTextField();
        campoSexoPaciente = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmc = new componentes.Numeros();
        jLabel5 = new javax.swing.JLabel();
        celularPaciente = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        telefonoPaciente = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        campoFechaDesde = new com.toedter.calendar.JDateChooser();
        campoFechaHasta = new com.toedter.calendar.JDateChooser();
        jLabel22 = new javax.swing.JLabel();
        campoNumeroDias = new componentes.Numeros();
        jLabel3 = new javax.swing.JLabel();
        HistoriaClinica = new componentes.Numeros();
        campoEstablecimiento = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        campoRutProfesional = new componentes.Rut();
        jLabel4 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        campoDiagnosticoProfesional = new javax.swing.JTextField();
        campoNombreProfesional = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        telefonoProfesional = new javax.swing.JTextField();
        celularProfesional = new javax.swing.JTextField();
        jLabel47 = new javax.swing.JLabel();
        botonAceptar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        campoMensajeria = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        contenedorPrestaciones = new javax.swing.JTable();
        botonAgregarPrestacion = new javax.swing.JButton();
        botonEliminarPrestacion = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jLabel49 = new javax.swing.JLabel();
        jLabel51 = new javax.swing.JLabel();
        jLabel53 = new javax.swing.JLabel();
        campoPrestacion = new javax.swing.JTextField();
        campoCodigo = new javax.swing.JComboBox();
        campoCantidad = new componentes.Numeros();
        jLabel55 = new javax.swing.JLabel();
        jLabel56 = new javax.swing.JLabel();
        jLabel58 = new javax.swing.JLabel();
        jLabel60 = new javax.swing.JLabel();
        jLabel61 = new javax.swing.JLabel();
        campoPrecio = new componentes.Dinero();
        campoTotal1 = new javax.swing.JTextField();
        mensajeriaInformacion1 = new javax.swing.JLabel();
        contenedorFonasa = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        campoRutProfesionalExterno = new componentes.Rut();
        jLabel23 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        campoNombreExterno = new javax.swing.JTextField();
        jLabel38 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        jLabel43 = new javax.swing.JLabel();
        telefonoExterno = new javax.swing.JTextField();
        celularExterno = new javax.swing.JTextField();
        especialidad = new javax.swing.JTextField();
        jLabel45 = new javax.swing.JLabel();
        campoNombreEstablecimientoExterno = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        campoNumeroProgramaComplementario = new componentes.Numeros();
        jLabel28 = new javax.swing.JLabel();
        campoTotal = new javax.swing.JTextField();
        jLabel31 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();

        DialogoVer.setMinimumSize(new java.awt.Dimension(600, 500));
        DialogoVer.setResizable(false);

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setMinimumSize(new java.awt.Dimension(700, 600));
        jPanel6.setPreferredSize(new java.awt.Dimension(752, 646));
        jPanel6.setRequestFocusEnabled(false);

        jLabel27.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Dipreca.png"))); // NOI18N

        jLabel30.setText("Nº:");

        etiquetaNumeroPrograma.setText("jLabel36");

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Beneficiario"));

        jLabel40.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel40.setText("Apellido paterno");

        EtiquetaApellidoPaternoPaciente.setText("jLabel38");

        jLabel42.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel42.setText("Apellido materno");

        etiquetaApellidoMaternoPaciente.setText("jLabel38");

        jLabel44.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel44.setText("Nombres");

        etiquetaNombresPaciente.setText("jLabel38");

        jLabel46.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel46.setText("Calle");

        etiquetaCalle.setText("jLabel38");

        jLabel48.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel48.setText("N°");

        etiquetaNumero.setText("jLabel38");

        jLabel50.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel50.setText("Población/villa");

        etiquetaPoblacion.setText("jLabel38");

        jLabel52.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel52.setText("Comuna");

        etiquetaComuna.setText("jLabel38");

        jLabel54.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel54.setText("Ciudad");

        etiquetaCiudad.setText("jLabel38");

        etiquetaRutPaciente.setText("jLabel38");

        jLabel57.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel57.setText("Rut");

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);

        etiquetaCMC.setText("jLabel38");

        jLabel59.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel59.setText("C.M.C");

        etiquetaEdad.setText("jLabel38");

        jLabel67.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel67.setText("Edad");

        etiquetaSexo.setText("jLabel38");

        jLabel69.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel69.setText("Sexo");

        jLabel71.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel71.setText("Teléfono");

        jLabel73.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel73.setText("Celular");

        etiquetaTelefonoPaciente.setText("jLabel17");

        etiquetaCelularPaciente.setText("jLabel28");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jLabel46))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(etiquetaCalle, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel48))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(etiquetaNumero)))
                .addGap(17, 17, 17)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(etiquetaPoblacion, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(etiquetaComuna, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)
                        .addComponent(etiquetaCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(97, 97, 97))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jLabel50)
                        .addGap(110, 110, 110)
                        .addComponent(jLabel52)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
                        .addComponent(jLabel54)
                        .addGap(126, 126, 126))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel57))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(etiquetaRutPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jLabel59))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaCMC, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(etiquetaEdad)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel67)))
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel69)
                        .addGap(99, 99, 99)
                        .addComponent(jLabel71))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(etiquetaSexo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(etiquetaTelefonoPaciente)))
                .addGap(61, 61, 61)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel73)
                    .addComponent(etiquetaCelularPaciente))
                .addContainerGap(108, Short.MAX_VALUE))
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jLabel40))
                    .addComponent(EtiquetaApellidoPaternoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jLabel42))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(etiquetaApellidoMaternoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel44))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(etiquetaNombresPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(263, Short.MAX_VALUE))
            .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel40)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(EtiquetaApellidoPaternoPaciente))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel44)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaNombresPaciente))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel42)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaApellidoMaternoPaciente)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel46)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(etiquetaCalle)
                            .addComponent(etiquetaNumero)))
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel48)
                        .addComponent(jLabel50)
                        .addComponent(jLabel52))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel54)
                        .addGap(5, 5, 5)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(etiquetaCiudad)
                            .addComponent(etiquetaComuna)))
                    .addComponent(etiquetaPoblacion, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addComponent(jLabel57)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(etiquetaRutPaciente))
                            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel67)
                                    .addGroup(jPanel7Layout.createSequentialGroup()
                                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel69)
                                            .addComponent(jLabel71)
                                            .addComponent(jLabel73))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(etiquetaEdad)
                                            .addComponent(etiquetaSexo)
                                            .addComponent(etiquetaTelefonoPaciente)
                                            .addComponent(etiquetaCelularPaciente))))
                                .addGroup(jPanel7Layout.createSequentialGroup()
                                    .addComponent(jLabel59)
                                    .addGap(8, 8, 8)
                                    .addComponent(etiquetaCMC))))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Profesional que Efectúa el tratamiento"));

        jLabel74.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel74.setText("Nombre del establecimiento");

        etiquetaNombreEstablecimiento.setText("jLabel38");

        jLabel80.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel80.setText("Día");

        etiquetaFechaDesde.setText("05");

        jLabel82.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel82.setText("Mes");

        jLabel84.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel84.setText("Año");

        jLabel87.setText("N° Días");

        jLabel102.setText("Fecha hospitalización o tratamiento");

        jSeparator10.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel103.setText("Desde");

        jSeparator11.setOrientation(javax.swing.SwingConstants.VERTICAL);

        etiquetaFechaHasta.setText("05");

        jLabel107.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel107.setText("Día");

        jLabel108.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel108.setText("Mes");

        jLabel109.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel109.setText("Año");

        jLabel110.setText("Hasta");

        jSeparator12.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator13.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator14.setOrientation(javax.swing.SwingConstants.VERTICAL);

        etiquetaNumeroDias.setText("N° Días");

        jLabel113.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel113.setText("Rut profesional");

        etiquetaRutProfesional.setText("jLabel38");

        etiquetaNombreProfesional.setText("jLabel38");

        jLabel117.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel117.setText("Nombre");

        jSeparator19.setOrientation(javax.swing.SwingConstants.VERTICAL);

        etiquetaDiagnostico1.setText("jLabel38");

        jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel88.setText("Historia Clinica N°");

        jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);

        etiquetaHistoriaClinica.setText("Historia Clinica");

        jSeparator22.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel17.setText("Diagnóstico");

        jSeparator17.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel74)
                    .addComponent(etiquetaNombreEstablecimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator19, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel113)
                    .addComponent(etiquetaRutProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator22, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(etiquetaNombreProfesional, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                    .addComponent(jLabel117)))
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel17)
                .addGap(32, 32, 32)
                .addComponent(jSeparator17, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(etiquetaDiagnostico1, javax.swing.GroupLayout.PREFERRED_SIZE, 551, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jSeparator8, javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel102)
                    .addGap(16, 16, 16)
                    .addComponent(jLabel103)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator10, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel8Layout.createSequentialGroup()
                            .addComponent(jLabel80)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel82)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel84))
                        .addComponent(etiquetaFechaDesde, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jSeparator11, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel110)
                    .addGap(9, 9, 9)
                    .addComponent(jSeparator12, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel8Layout.createSequentialGroup()
                            .addComponent(jLabel107)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel108)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel109))
                        .addComponent(etiquetaFechaHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jSeparator13, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel87)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator14, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(etiquetaNumeroDias, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel88, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(etiquetaHistoriaClinica, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap()))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel74, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaNombreEstablecimiento))
                    .addComponent(jSeparator19, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel113)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaRutProfesional))
                    .addComponent(jSeparator22, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel117)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaNombreProfesional)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel103)
                                    .addComponent(jLabel102)))
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jSeparator14, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator13, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator12, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator11, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator10, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                                    .addGap(8, 8, 8)
                                    .addComponent(jLabel110))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel87))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel80)
                                        .addComponent(jLabel82)
                                        .addComponent(jLabel84))
                                    .addGap(9, 9, 9)
                                    .addComponent(etiquetaFechaDesde))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel107)
                                        .addComponent(jLabel108)
                                        .addComponent(jLabel109))
                                    .addGap(9, 9, 9)
                                    .addComponent(etiquetaFechaHasta)))
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addGap(9, 9, 9)
                                .addComponent(etiquetaNumeroDias))
                            .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(jLabel88))))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(etiquetaHistoriaClinica)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator8, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(etiquetaDiagnostico1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSeparator17)))
        );

        tablaContenedoraPrestaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo de prestación", "Cant.", "Prestación", "Precio", "Total"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tablaContenedoraPrestaciones);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(0).setMinWidth(150);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(0).setPreferredWidth(150);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(0).setMaxWidth(150);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(1).setMinWidth(50);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(1).setPreferredWidth(50);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(1).setMaxWidth(50);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(3).setMinWidth(50);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(3).setPreferredWidth(50);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(3).setMaxWidth(50);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(4).setMinWidth(180);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(4).setPreferredWidth(180);
        tablaContenedoraPrestaciones.getColumnModel().getColumn(4).setMaxWidth(180);

        jLabel14.setText("N° Complementario:");

        etiquetaNumeroComplementario.setText("jLabel17");

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Profesional Médico que derivó e indicó el tratamiento"));

        jLabel116.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel116.setText("Nombre");

        etiquetaNombreProfesionalExterno.setText("jLabel38");

        jLabel114.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel114.setText("Rut profesional");

        jLabel118.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel118.setText("Especialidad");

        jLabel119.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel119.setText("Teléfono");

        jLabel120.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel120.setText("Celular");

        jSeparator9.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator16.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator20.setOrientation(javax.swing.SwingConstants.VERTICAL);

        etiquetaRutProfesionalExterno.setText("jLabel17");

        etiquetaEspecialidadExterno.setText("jLabel28");

        etiquetaTelefonoExterno.setText("jLabel29");

        etiquetaCelularExterno.setText("jLabel31");

        jSeparator21.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator15, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel116)
                    .addComponent(etiquetaNombreProfesionalExterno, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator9, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel114)
                    .addComponent(etiquetaRutProfesionalExterno))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator16, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel118))
                    .addComponent(etiquetaEspecialidadExterno))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator20, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel119)
                    .addComponent(etiquetaTelefonoExterno))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator21, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel120)
                    .addComponent(etiquetaCelularExterno))
                .addContainerGap(156, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel116)
                        .addGap(4, 4, 4)
                        .addComponent(etiquetaNombreProfesionalExterno))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel114)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(etiquetaRutProfesionalExterno))
                    .addComponent(jSeparator9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator16, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel118)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaEspecialidadExterno))
                    .addComponent(jSeparator20, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(jSeparator21, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel119)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaTelefonoExterno))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel120)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(etiquetaCelularExterno)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator15, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel29.setText("Total:");

        etiquetaTotal.setText("jLabel31");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel27)
                        .addGap(157, 157, 157)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel30)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(etiquetaNumeroComplementario, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(etiquetaNumeroPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(26, Short.MAX_VALUE))
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(26, 26, 26))
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(271, 271, 271)
                .addComponent(jLabel29)
                .addGap(32, 32, 32)
                .addComponent(etiquetaTotal)
                .addContainerGap(381, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel30)
                            .addComponent(etiquetaNumeroPrograma))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(etiquetaNumeroComplementario)))
                    .addComponent(jLabel27))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel29)
                    .addComponent(etiquetaTotal))
                .addGap(18, 18, 18)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        botonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Imprimir.png"))); // NOI18N
        botonImprimir.setText("Imprimir");
        botonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonImprimirActionPerformed(evt);
            }
        });

        botonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonCancel.setText("Cancelar");
        botonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout DialogoVerLayout = new javax.swing.GroupLayout(DialogoVer.getContentPane());
        DialogoVer.getContentPane().setLayout(DialogoVerLayout);
        DialogoVerLayout.setHorizontalGroup(
            DialogoVerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DialogoVerLayout.createSequentialGroup()
                .addContainerGap(560, Short.MAX_VALUE)
                .addComponent(botonImprimir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonCancel)
                .addContainerGap())
            .addGroup(DialogoVerLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        DialogoVerLayout.setVerticalGroup(
            DialogoVerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DialogoVerLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(DialogoVerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonCancel)
                    .addComponent(botonImprimir))
                .addContainerGap())
        );

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jPanel1.setMinimumSize(new java.awt.Dimension(949, 726));
        jPanel1.setPreferredSize(new java.awt.Dimension(949, 726));

        jLabel1.setText("Programa  Nº");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Beneficiario"));

        jLabel12.setText("Edad:");

        jLabel13.setText("Sexo:");

        jLabel34.setText("Rut:");

        jLabel35.setText("Apellido paterno:");

        jLabel37.setText("Apellido materno:");

        jLabel39.setText("Nombres:");

        jLabel10.setText("*");

        jLabel2.setText("C.M.C:");

        jLabel5.setText("Celular:");

        celularPaciente.setEditable(false);

        jLabel6.setText("Teléfono:");

        telefonoPaciente.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel34)
                        .addGap(18, 18, 18)
                        .addComponent(campoRutPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel35)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(celularPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoApellidoPaternoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(54, 54, 54)
                        .addComponent(telefonoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel37)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(100, 100, 100)
                        .addComponent(campoApellidoMaternoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel39)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(campoSexoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(57, 57, 57)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(campoEdadPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(campoNombresPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(70, 70, 70))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGap(5, 5, 5)
                                    .addComponent(jLabel34))
                                .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addComponent(campoRutPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(cmc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel35)
                            .addComponent(jLabel37)
                            .addComponent(campoApellidoPaternoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(campoApellidoMaternoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(campoNombresPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel39))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel12)
                                .addComponent(campoEdadPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel13)
                                .addComponent(jLabel6)
                                .addComponent(telefonoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(celularPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(campoSexoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Establecimiento"));

        jLabel18.setText("Nombre:");

        jLabel19.setText("Fecha tratamiento:");

        jLabel20.setText("Desde:");

        jLabel21.setText("Hasta:");

        campoFechaDesde.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                campoFechaDesdePropertyChange(evt);
            }
        });

        campoFechaHasta.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                campoFechaHastaPropertyChange(evt);
            }
        });

        jLabel22.setText("Nº días:");

        jLabel3.setText("Historia clinica n°:");

        campoEstablecimiento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ninguno" }));
        campoEstablecimiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoEstablecimientoActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/bitacora2.png"))); // NOI18N
        jButton1.setText("Crear");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addComponent(jLabel18))
                .addGap(6, 6, 6)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoFechaDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45)
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoFechaHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 21, Short.MAX_VALUE)
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addComponent(campoEstablecimiento, 0, 356, Short.MAX_VALUE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(campoNumeroDias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(HistoriaClinica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)))
                .addGap(217, 217, 217))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(campoEstablecimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel18)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(campoFechaDesde, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(campoFechaHasta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(HistoriaClinica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel22, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                        .addComponent(campoNumeroDias, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3)))
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Profesional tratante"));

        jLabel4.setText("Rut:");

        jLabel24.setText("Nombre:");

        jLabel25.setText("Diagnostico");

        jLabel26.setText("*");

        jLabel7.setText("Teléfono:");

        jLabel9.setText("Celular:");

        jLabel47.setText("*");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel25)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(campoRutProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoNombreProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addGap(12, 12, 12)
                        .addComponent(telefonoProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9)
                        .addGap(12, 12, 12)
                        .addComponent(celularProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(campoDiagnosticoProfesional))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel47)
                .addContainerGap(72, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(campoNombreProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel26)
                        .addComponent(jLabel24))
                    .addComponent(jLabel4)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(telefonoProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(celularProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9))
                    .addComponent(campoRutProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(campoDiagnosticoProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel47))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botonAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png"))); // NOI18N
        botonAceptar.setText("Agregar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        campoMensajeria.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        campoMensajeria.setText("Área de mensajería");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Prestaciones"));

        contenedorPrestaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Codigo de prestación", "Cantidad", "Prestación", "Precio", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(contenedorPrestaciones);

        botonAgregarPrestacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png"))); // NOI18N
        botonAgregarPrestacion.setToolTipText("Agregar prestación");
        botonAgregarPrestacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarPrestacionActionPerformed(evt);
            }
        });

        botonEliminarPrestacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Eliminar.png"))); // NOI18N
        botonEliminarPrestacion.setToolTipText("Eliminar prestación");
        botonEliminarPrestacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarPrestacionActionPerformed(evt);
            }
        });

        jLabel49.setText("Código de prestación:");

        jLabel51.setText("Cantidad:");

        jLabel53.setText("Prestación:");

        campoCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoCodigoActionPerformed(evt);
            }
        });

        jLabel55.setText("*");

        jLabel56.setText("*");

        jLabel58.setText("*");

        jLabel60.setText("Precio:");

        jLabel61.setText("Total:");

        campoPrecio.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                campoPrecioFocusLost(evt);
            }
        });

        campoTotal1.setEditable(false);

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel49)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel55)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel51)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel56, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel53)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoPrestacion, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel60)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel58, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel61)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel55)
                                .addComponent(campoCodigo)
                                .addComponent(jLabel51, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel49))
                            .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel53, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(campoPrestacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel60))
                            .addComponent(campoCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel61, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(campoTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(campoPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel58, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addContainerGap())
                    .addComponent(jLabel56, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 839, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(botonEliminarPrestacion)
                            .addComponent(botonAgregarPrestacion)))
                    .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(botonAgregarPrestacion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonEliminarPrestacion)
                        .addGap(37, 37, 37))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        mensajeriaInformacion1.setText("*Campos obligatorios");

        contenedorFonasa.setFont(new java.awt.Font("Tahoma", 1, 18));
        contenedorFonasa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Dipreca.png"))); // NOI18N

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder("Profesional derivador"));

        jLabel23.setText("Rut:");

        jLabel32.setText("Nombre:");

        jLabel33.setText("Especialidad");

        jLabel38.setText("*");

        jLabel41.setText("Teléfono:");

        jLabel43.setText("Celular:");

        jLabel45.setText("Nombre establecimiento:");

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel23)
                    .addComponent(jLabel33))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(campoRutProfesionalExterno, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel38, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(especialidad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jLabel32)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoNombreExterno, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jLabel45)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoNombreEstablecimientoExterno)))
                .addGap(18, 18, 18)
                .addComponent(jLabel41)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(telefonoExterno, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel43)
                .addGap(10, 10, 10)
                .addComponent(celularExterno, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel38)
                        .addComponent(jLabel32)
                        .addComponent(campoNombreExterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel41)
                        .addComponent(telefonoExterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel43)
                        .addComponent(celularExterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(campoRutProfesionalExterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel33)
                    .addComponent(especialidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel45)
                    .addComponent(campoNombreEstablecimientoExterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jLabel11.setText("Programa Complementario al N°");

        jLabel28.setText("Total:");

        campoTotal.setEditable(false);

        jLabel31.setText("*");

        jLabel36.setText("*");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(campoMensajeria, javax.swing.GroupLayout.DEFAULT_SIZE, 914, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(mensajeriaInformacion1, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 195, Short.MAX_VALUE)
                        .addComponent(jLabel28)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(198, 198, 198)
                        .addComponent(botonAceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonCancelar)
                        .addGap(12, 12, 12)))
                .addGap(22, 22, 22))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 930, Short.MAX_VALUE)
                    .addComponent(jPanel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 930, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(contenedorFonasa)
                        .addGap(342, 342, 342)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(campoNumeroProgramaComplementario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(campoNumeroPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(13, 13, 13)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel36, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel31, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(30, 30, 30))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(contenedorFonasa, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(campoNumeroPrograma, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel31, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel36, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(campoNumeroProgramaComplementario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(18, 18, 18)
                            .addComponent(jLabel11))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(mensajeriaInformacion1))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botonAceptar)
                        .addComponent(botonCancelar))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel28)))
                .addGap(18, 18, 18)
                .addComponent(campoMensajeria, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 956, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Closes the dialog
     */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        dispose = true;
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        this.normalizarMensajeria();
        if (camposObligatoriosLlenos()) {
            service.ProgramaDipreca sp = (service.ProgramaDipreca) obtenerProgramaDipreca(campoNumeroPrograma.getNumeros().getText());
            if (botonAceptar.getText().equalsIgnoreCase("Guardar")) {
                String anterior = "Número programa: " + sp.getNumeroPrograma() + "\n" + "Número complementario: " + sp.getNumeroComplementario() + "\n" + "Rut paciente: " + sp.getRutPaciente() + "\n" + "Rut profesional: " + sp.getRutProfesional() + "\n"
                        + "Establecimiento: " + sp.getNombreEstablecimiento() + "\n" + "Desde: " + sp.getFechaDesde() + "\n" + "Hasta: " + sp.getFechaHasta() + "\n" + "Historia n°: "
                        + sp.getHistoriaNumeo() + "\n" + "Número días: " + sp.getNDias() + "\n" + "Rut profesional externo:" + sp.getRutProfesionalExterno()
                        + "\n" + "Diagnóstico: " + sp.getDiagnostico();
                calcularCantidadSesiones(sp);
                modificarProg(sp);
                guardarPrestacionesMedicas();
                String posterior = "Número programa: " + sp.getNumeroPrograma() + "\n" + "Número complementario: " + sp.getNumeroComplementario() + "\n" + "Rut paciente: " + sp.getRutPaciente() + "\n" + "Rut profesional: " + sp.getRutProfesional() + "\n"
                        + "Establecimiento: " + sp.getNombreEstablecimiento() + "\n" + "Desde: " + sp.getFechaDesde() + "\n" + "Hasta: " + sp.getFechaHasta() + "\n" + "Historia n°: "
                        + sp.getHistoriaNumeo() + "\n" + "Número días: " + sp.getNDias() + "\n" + "Rut profesional externo:" + sp.getRutProfesionalExterno()
                        + "\n" + "diagnóstico: " + sp.getDiagnostico();
                registrar(Login.getUser(), "Programa médico", "Modificó programa DIPRECA: " + sp.getNumeroPrograma(), anterior, posterior);
                if (programa != null) {
                    programa.actualizarTabla();
                }
                cambiarEtiquetaMensajeria(Mensajeria.mensajeDeAccion("Programa medico dipreca", "modificar"), Color.black);
                this.dispose();
            } else if (botonAceptar.getText().equalsIgnoreCase("Imprimir")) {
                service.Privilegios p = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
                if (p.isImprimirProgramaMedicoDipreca()) {
                    try {
                        this.exportarPDF();
                        cambiarEtiquetaMensajeria(Mensajeria.mensajeDeAccion("Programa medico dipreca", "imprimir"), Color.black);
                        this.dispose();
                    } catch (Exception ex) {
                        Logger.getLogger(Paciente.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "No tiene permisos para esta acción, \n contacte al administrador para más información");
                }
            } else if (botonAceptar.getText().equalsIgnoreCase("Agregar")) {
                if (this.campoRutPaciente.isValido() && this.campoRutProfesional.isValido() && this.campoRutProfesionalExterno.isValido()) {
                    boolean existe = existePrograma(this.campoNumeroPrograma.getNumeros().getText());
                    if (existe == false) {
                        service.ProgramaDipreca p = new service.ProgramaDipreca();
                        p.setNumeroPrograma(this.campoNumeroPrograma.getNumeros().getText());
                        p.setDiagnostico(this.campoDiagnosticoProfesional.getText());
                        p.setFechaDesde(retornarDesde());
                        p.setFechaHasta(retornarHasta());
                        p.setHistoriaNumeo(this.HistoriaClinica.getNumeros().getText());
                        p.setNDias(this.campoNumeroDias.getNumeros().getText());
                        p.setNombreEstablecimiento((String) this.campoEstablecimiento.getSelectedItem());
                        p.setNumeroComplementario(this.campoNumeroProgramaComplementario.getNumeros().getText()); //id
                        p.setRutPaciente(campoRutPaciente.getRut().getText());
                        p.setRutProfesional(campoRutProfesional.getRut().getText());
                        p.setRutProfesionalExterno(this.campoRutProfesionalExterno.getRut().getText());
                        p.setCmcPaciente(this.cmc.getNumeros().getText());
                        p.setValorTotal(this.campoTotal.getText());
                        p.setVisible(true);
                        calcularCantidadSesiones(p);
                        agregarProgramaDipreca(p);
                        guardarPrestacionesMedicas();
                        String posterior = "Número programa: " + p.getNumeroPrograma() + "\n" + "Número complementario: " + p.getNumeroComplementario() + "\n" + "Rut paciente: " + p.getRutPaciente() + "\n" + "Rut profesional: " + p.getRutProfesional() + "\n"
                                + "Establecimiento: " + p.getNombreEstablecimiento() + "\n" + "Desde: " + p.getFechaDesde() + "\n" + "Hasta: " + p.getFechaHasta() + "\n" + "Historia n°: "
                                + p.getHistoriaNumeo() + "\n" + "Número días: " + p.getNDias() + "\n" + "Rut Profesional externo:" + p.getRutProfesionalExterno()
                                + "\n" + "Diagnóstico: " + p.getDiagnostico();
                        registrar(Login.getUser(), "Programa médico", "Agregó programa DIPRECA: " + p.getNumeroPrograma(), "No aplica", posterior);
                        if (programa != null) {
                            programa.actualizarTabla();
                        }
                        cambiarEtiquetaMensajeria(Mensajeria.mensajeDeAccion("Programa medico dipreca", "agregar"), Color.black);
                        this.dispose();
                    } else {
                        this.cambiarEtiquetaMensajeria(Mensajeria.mensajeEntidadExistente("Programa medico dipreca"), Color.red);
                    }
                } else {
                    if (!campoRutPaciente.isValido() || !campoRutProfesional.isValido() || !campoRutProfesionalExterno.isValido()) {
                        this.cambiarEtiquetaMensajeria(Mensajeria.mensajeRutValido(), Color.red);
                    } else {
                        this.cambiarEtiquetaMensajeria(Mensajeria.mensajeCamposObligatorios(), Color.red);
                    }
                }

            }

        } else if (!camposObligatoriosLlenos()) {
            this.cambiarEtiquetaMensajeria(Mensajeria.mensajeCamposObligatorios(), Color.red);
        }
    }//GEN-LAST:event_botonAceptarActionPerformed
    public String retornarDesde() {
        if (this.campoFechaDesde.getDate() != null) {
            return new SimpleDateFormat("dd-MM-yyyy").format(campoFechaDesde.getDate());
        } else {
            return "";
        }
    }

    public String retornarHasta() {
        if (this.campoFechaHasta.getDate() != null) {
            return new SimpleDateFormat("dd-MM-yyyy").format(campoFechaHasta.getDate());
        } else {
            return "";
        }
    }

    public boolean existePrograma(String numeroPrograma) {
        service.ProgramaDipreca pro = (ProgramaDipreca) obtenerProgramaDipreca(numeroPrograma);
        if (pro == null) {
            return false;
        } else {
            return true;
        }

    }
    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        this.dispose = true;
        this.dispose();
    }//GEN-LAST:event_botonCancelarActionPerformed

    private void botonAgregarPrestacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarPrestacionActionPerformed

        if (camposObligatoriosLlenosPrestacion()) {
            if (!campoPrecio.getDinero().getText().equals("") && !campoCantidad.getNumeros().getText().equals("")) {
                // calculo precio para total
                campoTotal1.setText(darFormatoDinero(Integer.toString(soloNumeros(campoPrecio.getDinero().getText()) * campoCantidad.getNumero())));
            }
            DefaultTableModel model = (DefaultTableModel) contenedorPrestaciones.getModel();
            Object fila[] = {"vacio", campoCodigo.getSelectedItem() + "", campoCantidad.getNumero() + "", campoPrestacion.getText() + "", campoPrecio.getDinero().getText() + "", campoTotal1.getText() + ""};
            model.addRow(fila);
            this.calcularTotal();
            cambiarEtiquetaMensajeria("Prestación agregada exitosamente", Color.black);
            this.limpiarCamposPrestacion();
        } else {
            cambiarEtiquetaMensajeria("Campos obligatorios sin llenar", Color.red);
        }
    }//GEN-LAST:event_botonAgregarPrestacionActionPerformed

    private void botonEliminarPrestacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarPrestacionActionPerformed
        DefaultTableModel model = (DefaultTableModel) contenedorPrestaciones.getModel();
        int confirmado = JOptionPane.showConfirmDialog(null, "¿Esta seguro de que quiere eliminar la prestación?");
        if (JOptionPane.OK_OPTION == confirmado) {
            if (model.getValueAt(contenedorPrestaciones.getSelectedRow(), 0) != null && !model.getValueAt(contenedorPrestaciones.getSelectedRow(), 0).equals("vacio")) {
                service.PrestacionMedica p = (service.PrestacionMedica) cargarPrestacionMedicaGeneral(new Long(Integer.parseInt((String) model.getValueAt(contenedorPrestaciones.getSelectedRow(), 0))));
                String nuevo = "Código: " + p.getCodigo() + "\n" + "Cantidad: " + p.getCantidad() + "\n" + "Número programa: " + p.getNumeroPrograma() + "\n" + "Tipo programa: " + p.getTipoPrograma() + "\n" + "Valor: " + p.getValor();
                registrar(Login.getUser(), "Programa médico", "Eliminó prestación código: " + p.getCodigo() + " a programa DIPRECA: " + p.getNumeroPrograma(), "No aplica", nuevo);
                eliminarPrestacionMedicaGeneral(new Long(Integer.parseInt((String) model.getValueAt(contenedorPrestaciones.getSelectedRow(), 0))));
            }
            model.removeRow(contenedorPrestaciones.getSelectedRow());
            this.calcularTotal();
            cambiarEtiquetaMensajeria("Prestación eliminada exitosamente", Color.black);
        }
    }//GEN-LAST:event_botonEliminarPrestacionActionPerformed

    private void campoFechaDesdePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_campoFechaDesdePropertyChange
        if (campoFechaHasta.getDate() != null) {
            if (isFechasValidas()) {
                normalizarMensajeria();
                calcularNumeroDias();
            } else {
                cambiarEtiquetaMensajeria("Fechas erroneas", Color.red);
                campoNumeroDias.getNumeros().setText("");
            }
        }
    }//GEN-LAST:event_campoFechaDesdePropertyChange

    private void campoFechaHastaPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_campoFechaHastaPropertyChange
        if (campoFechaDesde.getDate() != null) {
            if (isFechasValidas()) {
                normalizarMensajeria();
                calcularNumeroDias();
            } else {
                cambiarEtiquetaMensajeria("Fechas erroneas", Color.red);
                campoNumeroDias.getNumeros().setText("");
            }
        }
    }//GEN-LAST:event_campoFechaHastaPropertyChange

    private void botonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelActionPerformed
        this.DialogoVer.dispose();
    }//GEN-LAST:event_botonCancelActionPerformed

    private void botonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonImprimirActionPerformed
        try {
            this.exportarPDF();
        } catch (Exception ex) {
            Logger.getLogger(DialogoInfoProgramaMedicoDipreca.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.DialogoVer.dispose();
    }//GEN-LAST:event_botonImprimirActionPerformed
    public String retornarDinero(String dinero) {
        if (dinero.contains("$")) {
            return dinero; // quiere decir que ya tiene el formato de dinero
        } else {
            return darFormatoDinero(dinero);
        }

    }
    private void campoCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoCodigoActionPerformed
        //debo buscar el nombre de las prestaciones en la bd
        if (campoCodigo.getItemCount() != 0) {
            String cod = (String) campoCodigo.getSelectedItem();
            service.CodigosPrestaciones c = (service.CodigosPrestaciones) cargarCodigoPrestacion(cod);
            campoPrestacion.setText(c.getNombrePrestacion());
            if (c.getValorDJ() != null && !c.getValorDJ().equals("")) {
                this.campoPrecio.getDinero().setText(this.retornarDinero(c.getValorDJ()));
                if (!this.campoPrecio.getDinero().equals("") && !this.campoCantidad.getNumeros().getText().equals("")) {
                    campoTotal1.setText(retornarDinero(Integer.toString(soloNumeros(campoPrecio.getDinero().getText()) * campoCantidad.getNumero())));
                }
            } else {
                this.campoPrecio.getDinero().setText("");
                this.campoTotal1.setText("");
            }
        }
}//GEN-LAST:event_campoCodigoActionPerformed

    private void campoPrecioFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_campoPrecioFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_campoPrecioFocusLost

    private void campoEstablecimientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoEstablecimientoActionPerformed
        // TODO add your handling code here:
        if (campoEstablecimiento.getItemCount() != 0) {
            String cod = (String) campoEstablecimiento.getSelectedItem();
        }
    }//GEN-LAST:event_campoEstablecimientoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        normalizarMensajeria();
        DialogoAgregarEstablecimiento dia = new DialogoAgregarEstablecimiento(null, true, "");
        dia.setLocationRelativeTo(null);
        dia.setVisible(true);
        this.cargarEstablecimiento();
    }//GEN-LAST:event_jButton1ActionPerformed
    public void exportarPDF() throws Exception {

        Font fuenteTitulo = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        Font fuenteSubTitulo = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        Font fuenteTexto = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
        // agregar tabla antecedentes

        PdfPTable antecedentes = new PdfPTable(1);
        antecedentes.addCell(new PdfPCell(new Paragraph("ANTECEDENTES PARA CONFECCIONAR PROGRAMA DE ATENCIÓN DE SALUD", fuenteTitulo)));

        //beneficiario
        PdfPTable beneficiario = new PdfPTable(3);
        //datos direccion beneficiario
        beneficiario.addCell(new PdfPCell(new Paragraph("APELLIDO PATERNO", fuenteSubTitulo)));
        beneficiario.addCell(new PdfPCell(new Paragraph("APELLIDO MATERNO", fuenteSubTitulo)));
        beneficiario.addCell(new PdfPCell(new Paragraph("NOMBRE", fuenteSubTitulo)));
        beneficiario.addCell(new PdfPCell(new Paragraph(this.campoApellidoPaternoPaciente.getText(), fuenteTexto)));
        beneficiario.addCell(new PdfPCell(new Paragraph(this.campoApellidoMaternoPaciente.getText(), fuenteTexto)));
        beneficiario.addCell(new PdfPCell(new Paragraph(this.campoNombresPaciente.getText(), fuenteTexto)));
        service.Paciente p = (service.Paciente) cargarPaciente(this.campoRutPaciente.getRut().getText());
        PdfPTable direccion = new PdfPTable(5);
        direccion.addCell(new PdfPCell(new Paragraph("CALLE", fuenteSubTitulo)));
        direccion.addCell(new PdfPCell(new Paragraph("N°", fuenteSubTitulo)));
        direccion.addCell(new PdfPCell(new Paragraph("POBL. O VILLA", fuenteSubTitulo)));
        direccion.addCell(new PdfPCell(new Paragraph("COMUNA", fuenteSubTitulo)));
        direccion.addCell(new PdfPCell(new Paragraph("REGION", fuenteSubTitulo)));
        direccion.addCell(new PdfPCell(new Paragraph(p.getCalle(), fuenteTexto)));
        direccion.addCell(new PdfPCell(new Paragraph(p.getNumero(), fuenteTexto)));
        direccion.addCell(new PdfPCell(new Paragraph(p.getSector(), fuenteTexto)));
        direccion.addCell(new PdfPCell(new Paragraph(p.getComuna(), fuenteTexto)));
        direccion.addCell(new PdfPCell(new Paragraph(p.getRegion(), fuenteTexto)));
        service.Usuario pro = (service.Usuario) cargarUsuario(this.campoRutProfesional.getRut().getText());
        PdfPTable prestador = new PdfPTable(2);
        prestador.addCell(new PdfPCell(new Paragraph("RUT PRESTADOR", fuenteSubTitulo)));
        prestador.addCell(new PdfPCell(new Paragraph("NOMBRE PRESTADOR", fuenteSubTitulo)));
        prestador.addCell(new PdfPCell(new Paragraph(pro.getRut(), fuenteTexto)));
        prestador.addCell(new PdfPCell(new Paragraph(pro.getNombres() + " " + pro.getApellidoPaterno() + " " + pro.getApellidoMaterno(), fuenteTexto)));
        PdfPTable presta = new PdfPTable(5);
        presta.addCell(new PdfPCell(new Paragraph("COD PRESTACIÓN", fuenteSubTitulo)));
        presta.addCell(new PdfPCell(new Paragraph("CANTIDAD", fuenteSubTitulo)));
        presta.addCell(new PdfPCell(new Paragraph("PRESTACIÓN", fuenteSubTitulo)));
        presta.addCell(new PdfPCell(new Paragraph("VALOR", fuenteSubTitulo)));
        presta.addCell(new PdfPCell(new Paragraph("TOTAL", fuenteSubTitulo)));
        int cantidad = this.contenedorPrestaciones.getRowCount();
        for (int i = 0; i < cantidad; i++) {
            presta.addCell(new PdfPCell(new Paragraph(contenedorPrestaciones.getValueAt(i, 1).toString(), fuenteSubTitulo)));
            presta.addCell(new PdfPCell(new Paragraph(contenedorPrestaciones.getValueAt(i, 2).toString(), fuenteSubTitulo)));
            presta.addCell(new PdfPCell(new Paragraph(contenedorPrestaciones.getValueAt(i, 3).toString(), fuenteSubTitulo)));
            presta.addCell(new PdfPCell(new Paragraph(contenedorPrestaciones.getValueAt(i, 4).toString(), fuenteSubTitulo)));
            presta.addCell(new PdfPCell(new Paragraph(contenedorPrestaciones.getValueAt(i, 5).toString(), fuenteSubTitulo)));
        }
        //codigo prestacion cantidad prestacion valor total

        //profesional externo derivador
        PdfPTable externo = new PdfPTable(3);
        externo.addCell(new PdfPCell(new Paragraph("APELLIDO PATERNO", fuenteSubTitulo)));
        externo.addCell(new PdfPCell(new Paragraph("APELLIDO MATERNO", fuenteSubTitulo)));
        externo.addCell(new PdfPCell(new Paragraph("NOMBRE", fuenteSubTitulo)));
        service.ProfesionalExterno ext = (service.ProfesionalExterno) cargarProfesionalExterno(this.campoRutProfesionalExterno.getRut().getText());
        externo.addCell(new PdfPCell(new Paragraph(ext.getApellidoPaterno(), fuenteTexto)));
        externo.addCell(new PdfPCell(new Paragraph(ext.getApellidoMaterno(), fuenteTexto)));
        externo.addCell(new PdfPCell(new Paragraph(ext.getNombres(), fuenteTexto)));

        Document document = new Document();
        String dirArchivo = "noserepitenuncajamasjamasdipreca.pdf";
        FileOutputStream ficheroPdf = new FileOutputStream(dirArchivo);
        PdfWriter pd = PdfWriter.getInstance(document, ficheroPdf);
        pd.setInitialLeading(20);
        pd.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
        pd.setFullCompression();

        document.open();
        // agregar imagen
        try {
            Image foto = Image.getInstance(getClass().getResource("/GUI/Img/Dipreca.png"));
            foto.scaleToFit(100, 100);
            foto.setAlignment(Chunk.ALIGN_LEFT);
            document.add(foto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(antecedentes);
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("PROGRAMA COMPLEMENTARIO AL N°: " + this.campoNumeroProgramaComplementario.getNumeros().getText(), fuenteTexto));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("BENEFICIARIO", fuenteTitulo));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(beneficiario);
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(direccion);
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("RUT: " + this.campoRutPaciente.getRut().getText() + "     " + "C.M.C: " + this.cmc.getNumeros().getText() + "     " + "CELULAR: " + this.celularPaciente.getText(), fuenteTexto));
        document.add(new Paragraph("EDAD: " + this.campoEdadPaciente.getText() + "     " + "Sexo: " + this.campoSexoPaciente.getText() + "     " + "TELEFONO: " + this.telefonoPaciente.getText(), fuenteTexto));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("PROFESIONAL QUE EFECTÚA EL TRATAMIENTO", fuenteTitulo));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("NOMBRE DEL ESTABLECIMIENTO:      " + (String) this.campoEstablecimiento.getSelectedItem(), fuenteTexto));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(prestador);
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("DOMICILIO:        " + pro.getCalle() + " " + pro.getNumero(), fuenteSubTitulo));
        document.add(new Paragraph("FIRMA PROFESIONAL TRATANTE:   ____________________", fuenteTexto));
        document.add(new Paragraph("FECHA TRATAMIENTO   DESDE: " + this.retornarDesde() + "   HASTA:" + this.retornarHasta() + "   N° Días:" + this.campoNumeroDias.getNumeros().getText(), fuenteTexto));
        document.add(new Paragraph("HISTORIA CLINICA N°:   " + this.HistoriaClinica.getNumeros().getText(), fuenteTexto));
        document.add(new Paragraph("DIAGNÓSTICO:   " + this.campoDiagnosticoProfesional.getText(), fuenteTexto));
        document.add(new Paragraph(" ", fuenteTexto));
        if (cantidad > 0) {
            document.add(presta);
        }
        document.add(new Paragraph("TOTAL: " + this.campoTotal.getText(), fuenteSubTitulo));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("PROFESIONAL MÉDICO QUE DERIVÓ E INDICÓ TRATAMIENTO", fuenteTitulo));
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(externo);
        document.add(new Paragraph(" ", fuenteTexto));
        document.add(new Paragraph("RUT: " + this.campoRutProfesionalExterno.getRut().getText() + "   ESPECIALIDAD:  " + this.especialidad.getText() + " CELULAR: " + this.celularExterno.getText() + " TELÉFONO: " + this.telefonoExterno.getText(), fuenteTexto));
        document.add(new Paragraph("NOMBRE ESTABLECIMIENTO: " + this.campoNombreEstablecimientoExterno.getText(), fuenteTexto));

        document.close();

        ficheroPdf.close();
        PdfDecoder pdf = null;
        try {
            PrintService[] service = PrinterJob.lookupPrintServices();
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintService(service[0]);

            Paper paper = new Paper();
            paper.setSize(595, 842);
            paper.setImageableArea(0, 0, 595, 842);
            PageFormat pf = printJob.defaultPage();
            pf.setPaper(paper);

            pdf = new PdfDecoder(true);
            pdf.openPdfFile(dirArchivo);
            pdf.setPageFormat(pf);

            printJob.setPageable(pdf);
            printJob.printDialog();
            printJob.print();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            pdf.closePdfFile();
        }



    }

    public String eligeDireccionArchivo() {
        String dirArchivo = "";
        JFileChooser jFileChooser1 = new JFileChooser();
        jFileChooser1.setDialogTitle("Guardar archivo:");
        jFileChooser1.setVisible(true);

        int r = jFileChooser1.showSaveDialog(null);
        if (r == JFileChooser.APPROVE_OPTION) {
            File file = jFileChooser1.getSelectedFile();
            dirArchivo = String.valueOf(file);
        }
        dirArchivo = dirArchivo.replace('\\', '/') + ".pdf";
        return dirArchivo;

    }

    public String generarEspacios(String espacios) {
        String espacio = " ";
        int cantidad = espacios.length();
        for (int i = 0; i < cantidad; i++) {
            espacio += " ";
        }
        return espacio;
    }

    public void abrirArchivo(String direccion) {
        //Abre el documento pdf
        try {
            File file = new File(direccion);
            Desktop.getDesktop().open(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean isFechasValidas() {
        if (campoFechaDesde.getDate() != null && campoFechaHasta.getDate() != null) {
            if (!campoFechaHasta.getDate().before(campoFechaDesde.getDate())) {
                return true;
            }
        }
        return false;
    }

    public void calcularNumeroDias() {
        if (campoFechaDesde.getDate() != null && campoFechaHasta.getDate() != null) {
            int cont = 0;
            Calendar nextDate = new GregorianCalendar();
            nextDate.setTime(campoFechaDesde.getDate());
            while (!(nextDate.get(Calendar.DAY_OF_MONTH) == campoFechaHasta.getCalendar().get(Calendar.DAY_OF_MONTH)
                    && nextDate.get(Calendar.MONTH) == campoFechaHasta.getCalendar().get(Calendar.MONTH)
                    && nextDate.get(Calendar.YEAR) == campoFechaHasta.getCalendar().get(Calendar.YEAR))) {
                nextDate.add(Calendar.DAY_OF_MONTH, 1);

                cont++;
            }
            campoNumeroDias.getNumeros().setText(cont + "");
        }
    }

    public void numeroDiasFocusLost() {
        campoNumeroDias.getNumeros().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                if (campoFechaDesde.getDate() != null) {
                    calcularFecha();
                }

            }
        });
    }

    public void calcularFecha() {
        int cont = 0;
        Calendar nextDate = new GregorianCalendar();
        nextDate.setTime(campoFechaDesde.getDate());
        while (cont != campoNumeroDias.getNumero()) {
            nextDate.add(Calendar.DAY_OF_MONTH, 1);
            cont++;
        }
        campoFechaHasta.setDate(nextDate.getTime());
    }

    public void rutPacienteFocusLost() {
        normalizarMensajeria();
        campoRutPaciente.getRut().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                normalizarMensajeria();
                limpiarCamposPaciente();
                if (!campoRutPaciente.isValido() && !campoRutPaciente.getRut().getText().equals("")) {
                    cambiarEtiquetaMensajeria("Debe ingresar un rut válido ", Color.red);
                    campoRutPaciente.getRut().requestFocus();
                    limpiarCamposPaciente();
                } else if (campoRutPaciente.isValido() && !dispose) {
                    normalizarMensajeria();
                    service.Paciente p = (service.Paciente) cargarPaciente(campoRutPaciente.getRut().getText());
                    if (p != null) {
                        p = (service.Paciente) cargarPaciente(campoRutPaciente.getRut().getText());
                        llenarCamposPaciente(p);
                    } else if (p == null) {
                        int confirmado = JOptionPane.showConfirmDialog(null, "El paciente no esta registrado, ¿desea hacerlo?");
                        if (JOptionPane.OK_OPTION == confirmado) {
                            try {
                                DialogoInfoPaciente dip = new DialogoInfoPaciente(null, true, null);
                                dip.setLocationRelativeTo(null);
                                dip.limpiarCampos();
                                dip.setTitle("Agregar Paciente");
                                dip.getBotonAceptar().setText("Agregar");
                                dip.getBotonAceptar().setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
                                dip.getBotonCancelar().setText("Cancelar");
                                dip.rut.getRut().setText(campoRutPaciente.getRut().getText());
                                dip.setVisible(true);
                                p = (service.Paciente) cargarPaciente(campoRutPaciente.getRut().getText());
                                if (p != null) {
                                    llenarCamposPaciente(p);
                                }
                            } catch (FileNotFoundException ex) {
                                Logger.getLogger(DialogoAgregarCita.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(DialogoAgregarCita.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        } else {
                            limpiarCamposPaciente();
                        }
                    }

                }
            }
        });

    }

    public void llenarCamposPaciente(service.Paciente p) {
        if (p != null) {
            campoApellidoPaternoPaciente.setText(p.getApellidoPaterno());
            campoApellidoMaternoPaciente.setText(p.getApellidoMaterno());
            campoNombresPaciente.setText(p.getNombres());
            campoEdadPaciente.setText("" + calcularEdad(p.getFechaNac()));
            campoSexoPaciente.setText(p.getSexo());//falta sexo en paciente
            this.telefonoPaciente.setText(p.getTelefono());
            this.celularPaciente.setText(p.getCelular());
        }
    }

    public void limpiarCamposPaciente() {

        campoApellidoPaternoPaciente.setText("");
        campoApellidoMaternoPaciente.setText("");
        campoNombresPaciente.setText("");
        campoEdadPaciente.setText("");
        campoSexoPaciente.setText("");//falta sexo en paciente
        this.telefonoPaciente.setText("");
        this.celularPaciente.setText("");

    }

    public void rutProfesionalFocusLost() {
        normalizarMensajeria();
        campoRutProfesional.getRut().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                normalizarMensajeria();
                limpiarCamposProfesional();
                if (!campoRutProfesional.isValido() && !campoRutProfesional.getRut().getText().equals("")) {
                    cambiarEtiquetaMensajeria("Debe ingresar un rut válido", Color.red);
                    campoRutProfesional.getRut().requestFocus();
                    limpiarCamposProfesional();
                } else if (campoRutProfesional.isValido() && !dispose) {
                    normalizarMensajeria();
                    service.Usuario u = (service.Usuario) cargarUsuario(campoRutProfesional.getRut().getText());
                    if (u != null) {
                        u = (service.Usuario) cargarUsuario(campoRutProfesional.getRut().getText());
                        llenarCamposProfesional(u);
                    } else if (u == null) {
                        int confirmado = JOptionPane.showConfirmDialog(null, "El profesional no esta registrado, ¿desea hacerlo?");
                        if (JOptionPane.OK_OPTION == confirmado) {
                            DialogoInfoUsuarioProfesional moduloUsuario = new DialogoInfoUsuarioProfesional(null, true, null);
                            moduloUsuario.limpiarCampos();
                            moduloUsuario.habilitarCampos(true);
                            moduloUsuario.setTitle("Agregar Usuario");
                            moduloUsuario.setModal(true);
                            moduloUsuario.campoTipoCuenta.setEnabled(false);
                            moduloUsuario.botonFormularioAccion.setText("Agregar");
                            moduloUsuario.botonFormularioAccion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
                            moduloUsuario.estados.clear();
                            moduloUsuario.disponibilidad.clear();
                            moduloUsuario.campoRut.getRut().setText(campoRutProfesional.getRut().getText());
                            moduloUsuario.setVisible(true);
                            u = (service.Usuario) cargarUsuario(campoRutProfesional.getRut().getText());
                            llenarCamposProfesional(u);

                        } else {
                            limpiarCamposProfesional();
                        }
                    }

                }
            }
        });
    }

    public void rutProfesionalExternoFocusLost() {
        normalizarMensajeria();
        this.campoRutProfesionalExterno.getRut().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                normalizarMensajeria();
                limpiarCamposProfesionalExterno();
                if (!campoRutProfesionalExterno.isValido() && !campoRutProfesionalExterno.getRut().getText().equals("")) {
                    cambiarEtiquetaMensajeria("Debe ingresar un rut válido", Color.red);
                    campoRutProfesionalExterno.getRut().requestFocus();
                    limpiarCamposProfesionalExterno();
                } else if (campoRutProfesionalExterno.isValido() && !dispose) {
                    normalizarMensajeria();
                    service.ProfesionalExterno u = (service.ProfesionalExterno) cargarProfesionalExterno(campoRutProfesionalExterno.getRut().getText());
                    if (u != null) {
                        u = (service.ProfesionalExterno) cargarProfesionalExterno(campoRutProfesionalExterno.getRut().getText());
                        llenarCamposProfesionalExterno(u);
                    } else if (u == null) {
                        int confirmado = JOptionPane.showConfirmDialog(null, "El profesional Externo no esta registrado, ¿desea hacerlo?");
                        if (JOptionPane.OK_OPTION == confirmado) {
                            DialogoInfoProfesionalExterno moduloUsuario = new DialogoInfoProfesionalExterno(null, true, null);
                            moduloUsuario.setLocationRelativeTo(null);
                            moduloUsuario.limpiarCampos();
                            moduloUsuario.habilitarCampos(true);
                            moduloUsuario.setTitle("Agregar Profesional Externo");
                            moduloUsuario.botonFormularioAccion.setText("Agregar");
                            moduloUsuario.botonFormularioAccion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
                            moduloUsuario.getCampoRut().getRut().setText(campoRutProfesionalExterno.getRut().getText());
                            moduloUsuario.botonFormularioSalida.setText("Cancelar");
                            moduloUsuario.camposObligatoriosVisibles(true);
                            moduloUsuario.setVisible(true);
                            u = (service.ProfesionalExterno) cargarProfesionalExterno(campoRutProfesionalExterno.getRut().getText());
                            if (u != null) {
                                llenarCamposProfesionalExterno(u);
                            }
                        } else {
                            limpiarCamposProfesionalExterno();
                        }
                    }

                }
            }
        });

    }

    public void llenarCamposProfesional(service.Usuario u) {

        if (u != null) {
            campoNombreProfesional.setText(u.getNombres() + " " + u.getApellidoPaterno() + " " + u.getApellidoMaterno());
            this.telefonoProfesional.setText(u.getTelefono());
            this.celularProfesional.setText(u.getCelular());
        }
    }

    public void limpiarCamposProfesional() {

        campoNombreProfesional.setText("");
        this.telefonoProfesional.setText("");
        this.celularProfesional.setText("");

    }

    public void llenarCamposProfesionalExterno(service.ProfesionalExterno u) {
        if (u != null) {
            this.campoNombreExterno.setText(u.getNombres() + " " + u.getApellidoPaterno() + " " + u.getApellidoMaterno());
            this.telefonoExterno.setText(u.getTelefono());
            this.celularExterno.setText(u.getCelular());
            this.especialidad.setText(u.getEspecialidad());
            this.campoNombreEstablecimientoExterno.setText(u.getLugarDeTrabajo());
        }

    }

    public void limpiarCamposProfesionalExterno() {

        this.campoNombreExterno.setText("");
        this.telefonoExterno.setText("");
        this.celularExterno.setText("");
        this.especialidad.setText("");
        this.campoNombreEstablecimientoExterno.setText("");


    }

    public void numeroProgramaFocusLost() {
        campoNumeroPrograma.getNumeros().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                if (!isNumeroProgramaValido()) {
                    cambiarEtiquetaMensajeria("El número de programa ya existe", Color.red);
                    campoNumeroPrograma.getNumeros().requestFocus();
                }
            }
        });
    }

    public void numeroProgramaComplementarioFocusLost() {
        campoNumeroProgramaComplementario.getNumeros().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent fe) {
            }

            @Override
            public void focusLost(FocusEvent fe) {
                if (isNumeroProgramaComplementarioValido()) {
                    cambiarEtiquetaMensajeria("El número de programa complementario no existe", Color.red);
                    campoNumeroPrograma.getNumeros().requestFocus();
                }
            }
        });
    }

    public boolean isNumeroProgramaValido() {
        boolean isValido = true;
        service.ProgramaDipreca p = (service.ProgramaDipreca) obtenerProgramaDipreca(campoNumeroPrograma.getNumeros().getText());
        if (p != null) {
            isValido = false;
        }
        return isValido;
    }

    public boolean isNumeroProgramaComplementarioValido() {
        boolean isValido = true;
        service.ProgramaMedicoFonasa p = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(campoNumeroProgramaComplementario.getNumeros().getText());
        if (p != null) {
            isValido = false;
        }
        return isValido;
    }

    public void normalizarMensajeria() {
        campoMensajeria.setText("Área de mensajería");
        campoMensajeria.setForeground(Color.black);
    }

    public void limpiarCampos() {
        // numero pograma
        this.campoNumeroPrograma.getNumeros().setText("");
        this.campoNumeroProgramaComplementario.getNumeros().setText("");
        //datos paciente
        this.campoRutPaciente.getRut().setText("");
        this.campoApellidoMaternoPaciente.setText("");
        this.campoApellidoPaternoPaciente.setText("");
        this.campoNombresPaciente.setText("");
        this.campoEdadPaciente.setText("");
        this.campoSexoPaciente.setText("");
        this.cmc.getNumeros().setText("");
        this.telefonoPaciente.setText("");
        this.celularPaciente.setText("");
        //nombre establecimiento
        this.campoEstablecimiento.setSelectedIndex(0);
        //tratamiento
        this.campoFechaDesde.setDate(null);
        this.campoFechaHasta.setDate(null);
        this.campoNumeroDias.getNumeros().setText("");
        this.HistoriaClinica.getNumeros().setText("");
        // profesional
        this.campoRutProfesional.getRut().setText("");
        this.campoNombreProfesional.setText("");
        this.telefonoProfesional.setText("");
        this.celularProfesional.setText("");
        //profesional Externo
        this.campoRutProfesionalExterno.getRut().setText("");
        this.campoNombreExterno.setText("");
        this.telefonoExterno.setText("");
        this.celularExterno.setText("");
        this.especialidad.setText("");
        //diagnostico
        this.campoDiagnosticoProfesional.setText("");
        this.campoTotal.setText("");
        this.campoNombreEstablecimientoExterno.setText("");

        limpiarTabla();
        normalizarMensajeria();
    }

    public JButton getBotonAceptar() {
        return this.botonAceptar;
    }

    public JButton getBotonCancelar() {
        return this.botonCancelar;
    }

    public void habilitarCampos() {
        this.mostrarCampos();
        this.jButton1.setEnabled(true);
        this.campoNumeroPrograma.getNumeros().setEnabled(true);
        this.campoNumeroProgramaComplementario.getNumeros().setEnabled(true);
        this.campoRutPaciente.getRut().setEnabled(true);
        this.campoRutProfesional.getRut().setEnabled(true);
        this.cmc.getNumeros().setEnabled(true);
        this.campoEstablecimiento.setEnabled(true);
        this.campoFechaDesde.setEnabled(true);
        this.campoFechaHasta.setEnabled(true);
        this.HistoriaClinica.getNumeros().setEnabled(true);
        this.campoNumeroDias.getNumeros().setEnabled(true);
        this.campoRutProfesionalExterno.getRut().setEnabled(true);
        this.campoDiagnosticoProfesional.setEnabled(true);
        contenedorPrestaciones.setEnabled(true);
        botonAgregarPrestacion.setEnabled(true);
        botonEliminarPrestacion.setEnabled(true);
        this.campoCodigo.setEnabled(true);
        this.campoCantidad.getNumeros().setEnabled(true);
        this.campoPrecio.getDinero().setEnabled(true);

    }

    public void inhabilitarCampos() {
        // numero pograma
        this.ocultarCampos();
        this.jButton1.setEnabled(false);
        this.campoNumeroPrograma.getNumeros().setEnabled(false);
        this.campoNumeroProgramaComplementario.getNumeros().setEnabled(false);
        //datos paciente
        this.campoRutPaciente.getRut().setEnabled(false);
        this.campoApellidoMaternoPaciente.setEnabled(false);
        this.campoApellidoPaternoPaciente.setEnabled(false);
        this.campoNombresPaciente.setEnabled(false);
        this.campoEdadPaciente.setEnabled(false);
        this.campoSexoPaciente.setEnabled(false);
        this.cmc.getNumeros().setEnabled(false);
        this.telefonoPaciente.setEnabled(false);
        this.celularPaciente.setEnabled(false);
        //nombre establecimiento
        this.campoEstablecimiento.setEnabled(false);
        //tratamiento
        this.campoFechaDesde.setEnabled(false);
        this.campoFechaHasta.setEnabled(false);
        this.campoNumeroDias.getNumeros().setEnabled(false);
        this.HistoriaClinica.getNumeros().setEnabled(false);
        // profesional
        this.campoRutProfesional.getRut().setEnabled(false);
        this.campoNombreProfesional.setEnabled(false);
        this.telefonoProfesional.setEnabled(false);
        this.celularProfesional.setEnabled(false);
        //profesional Externo
        this.campoRutProfesionalExterno.getRut().setEnabled(false);
        this.campoNombreExterno.setEnabled(false);
        this.telefonoExterno.setEnabled(false);
        this.celularExterno.setEnabled(false);
        this.especialidad.setEnabled(false);
        //diagnostico
        this.campoDiagnosticoProfesional.setEnabled(false);
        this.contenedorPrestaciones.setEnabled(false);

        this.botonAgregarPrestacion.setEnabled(false);
        this.botonEliminarPrestacion.setEnabled(false);
        this.campoNombreEstablecimientoExterno.setEnabled(false);
        this.campoCodigo.setEnabled(false);
        this.campoCantidad.getNumeros().setEnabled(false);
        this.campoPrecio.getDinero().setEnabled(false);
    }

    public void rutFocusLost() {
        this.rutPacienteFocusLost();
        this.rutProfesionalFocusLost();
        this.rutProfesionalExternoFocusLost();
    }

    public void cambiarEtiquetaMensajeria(String mensaje, Color color) {
        campoMensajeria.setText(mensaje);
        campoMensajeria.setForeground(color);
    }

    public boolean camposObligatoriosLlenos() {
        boolean b = false;
        if (!campoNumeroPrograma.getNumeros().getText().equals("")
                && !this.campoNumeroProgramaComplementario.getNumeros().getText().equals("")
                && !campoRutPaciente.getRut().getText().equals("")
                && !this.campoNombreProfesional.getText().equals("")
                && !this.campoNombreExterno.getText().equals("")
                && !this.campoNombresPaciente.getText().equals("")
                && !campoRutProfesional.getRut().getText().equals("")
                && !this.campoRutProfesionalExterno.getRut().getText().equals("")
                && !this.campoDiagnosticoProfesional.getText().equals("")) {

            b = true;
        }
        return b;
    }

    public int calcularEdad(String fecha) {
        String datetext = fecha;
        try {
            Calendar birth = new GregorianCalendar();
            Calendar today = new GregorianCalendar();
            int age = 0;
            int factor = 0;
            Date birthDate = new SimpleDateFormat("dd-MM-yyyy").parse(datetext);
            Date currentDate = new Date(); //current date
            birth.setTime(birthDate);
            today.setTime(currentDate);
            if (today.get(Calendar.MONTH) <= birth.get(Calendar.MONTH)) {
                if (today.get(Calendar.MONTH) == birth.get(Calendar.MONTH)) {
                    if (today.get(Calendar.DATE) > birth.get(Calendar.DATE)) {
                        factor = -1; //Aun no celebra su cumpleaÃ±os
                    }
                } else {
                    factor = -1; //Aun no celebra su cumpleaÃ±os
                }
            }
            age = (today.get(Calendar.YEAR) - birth.get(Calendar.YEAR)) + factor;
            if (age != -1) {
                return age;
            } else {
                return 0;
            }
        } catch (ParseException e) {
            return -1;
        }

    }

    public void ocultarColumnaID() {
        contenedorPrestaciones.getColumnModel().getColumn(0).setMaxWidth(0);
        contenedorPrestaciones.getColumnModel().getColumn(0).setMinWidth(0);
        contenedorPrestaciones.getColumnModel().getColumn(0).setPreferredWidth(0);
    }

    private void guardarPrestacionesMedicas() {
        for (int i = 0; i < contenedorPrestaciones.getRowCount(); i++) {
            if (contenedorPrestaciones.getModel().getValueAt(i, 0).equals("vacio")) {
                service.PrestacionMedica p = new service.PrestacionMedica();
                p.setCodigo((String) contenedorPrestaciones.getModel().getValueAt(i, 1));
                p.setCantidad(Integer.parseInt((String) contenedorPrestaciones.getModel().getValueAt(i, 2)));
                p.setNumeroPrograma(campoNumeroPrograma.getNumeros().getText()); // asigno id o numero de programa a una prestacion
                p.setTipoPrograma("DIPRECA");
                p.setValor((String) contenedorPrestaciones.getModel().getValueAt(i, 5));
                p.setNivel(0);
                agregarPrestacionMedicaGeneral(p);
                String nuevo = "Código: " + p.getCodigo() + "\n" + "Cantidad: " + p.getCantidad() + "\n" + "Número programa: " + p.getNumeroPrograma() + "\n" + "Tipo programa: " + p.getTipoPrograma() + "\n" + "Valor: " + p.getValor();
                registrar(Login.getUser(), "Programa médico", "Agregó prestación código: " + p.getCodigo() + " a programa DIPRECA: " + p.getNumeroPrograma(), "No aplica", nuevo);
            }
        }
        this.limpiarTabla();
    }

    public void llenarCampos(service.ProgramaDipreca p) {
        try {
            campoNumeroPrograma.getNumeros().setText(p.getNumeroPrograma() + "");
            this.campoNumeroProgramaComplementario.getNumeros().setText(p.getNumeroComplementario() + "");
            campoRutPaciente.getRut().setText(p.getRutPaciente());
            service.Paciente paciente = (service.Paciente) cargarPaciente(p.getRutPaciente());
            llenarCamposPaciente(paciente);
            this.cmc.getNumeros().setText(p.getCmcPaciente());
            this.campoEstablecimiento.setSelectedItem(p.getNombreEstablecimiento());
            campoFechaDesde.setDate(llenarFecha(p.getFechaDesde()));
            campoFechaHasta.setDate(llenarFecha(p.getFechaHasta()));
            calcularNumeroDias();
            this.HistoriaClinica.getNumeros().setText(p.getHistoriaNumeo());
            campoRutProfesional.getRut().setText(p.getRutProfesional());
            service.Usuario profesional = (service.Usuario) cargarUsuario(p.getRutProfesional());
            llenarCamposProfesional(profesional);
            service.ProfesionalExterno externo = (service.ProfesionalExterno) cargarProfesionalExterno(p.getRutProfesionalExterno());
            llenarCamposProfesionalExterno(externo);
            campoDiagnosticoProfesional.setText(p.getDiagnostico());
            //derivador o profesional externo
            this.campoRutProfesionalExterno.getRut().setText(p.getRutProfesionalExterno());
            actualizarTabla(p);
        } catch (ParseException ex) {
            Logger.getLogger(DialogoInfoProgramaMedicoDipreca.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public Date llenarFecha(String fecha) throws ParseException {
        if (!fecha.equals("")) {
            return new SimpleDateFormat("dd-MM-yyyy").parse(fecha);
        } else {
            return null;
        }

    }
    /*
     * puede ocurrir un problema de referencia
     */

    public void llenarPaciente(String rut) {
        service.Paciente paciente = (service.Paciente) cargarPaciente(rut);
        this.campoRutPaciente.getRut().setText(rut);
        llenarCamposPaciente(paciente);
        this.campoRutPaciente.getRut().requestFocus();
    }

    public void actualizarTabla(service.ProgramaDipreca p) {
        this.limpiarTabla();
        int total = 0;
        List<service.PrestacionMedica> prestaciones = listarPrestacionesMedicasGeneral();
        int j = 0;
        for (int i = 0; i < prestaciones.size(); i++) {
            if (prestaciones.get(i).getNumeroPrograma().equals(p.getNumeroPrograma()) && prestaciones.get(i).getTipoPrograma().equals("DIPRECA")) {
                this.agregarFila();
                service.CodigosPrestaciones codigo = (CodigosPrestaciones) cargarCodigoPrestacion(prestaciones.get(i).getCodigo());
                contenedorPrestaciones.setValueAt(prestaciones.get(i).getId() + "", j, 0);
                contenedorPrestaciones.setValueAt(prestaciones.get(i).getCodigo() + "", j, 1);
                contenedorPrestaciones.setValueAt(prestaciones.get(i).getCantidad() + "", j, 2);
                contenedorPrestaciones.setValueAt(codigo.getNombrePrestacion() + "", j, 3);
                contenedorPrestaciones.setValueAt(this.retornarDinero(realizarValor(prestaciones.get(i).getValor(), prestaciones.get(i).getCantidad())) + "", j, 4);
                contenedorPrestaciones.setValueAt(this.retornarDinero(Integer.toString(soloNumeros((String) contenedorPrestaciones.getValueAt(j, 4)) * prestaciones.get(i).getCantidad())) + "", j, 5);
                total += soloNumeros((String) contenedorPrestaciones.getValueAt(j, 5));
                j++;
            }
        }
        this.campoTotal.setText(darFormatoDinero(Integer.toString(total)));
    }

    public int soloNumeros(String dinero) {
        return Integer.parseInt(dinero.replace("$", "").replace(".", ""));
    }
    /*
     * funcion que arregla problema de campo precio en total
     */

    public String realizarValor(String total, int cantidad) {
        if (cantidad > 0) {
            return Integer.toString(soloNumeros(total) / cantidad);
        } else {
            return "0";
        }

    }

    public String darFormatoDinero(String num) {
        String a = "";
        int con = 0;
        for (int i = num.length() - 1; i >= 0; i--) {
            if (con == 2 && i > 0) {
                con = 0;
                a = a + num.charAt(i) + ".";
            } else {
                a = a + num.charAt(i);
                con++;
            }
        }
        String b = "";
        for (int i = a.length() - 1; i >= 0; i--) {
            b = b + a.charAt(i);
        }

        return "$" + b;

    }

    public void limpiarTabla() {
        DefaultTableModel temp = (DefaultTableModel) contenedorPrestaciones.getModel();
        for (int i = contenedorPrestaciones.getRowCount() - 1; i >= 0; i--) {
            System.out.println(i);
            temp.removeRow(i);
        }
    }

    public void calcularTotal() {
        DefaultTableModel temp = (DefaultTableModel) contenedorPrestaciones.getModel();
        int total = 0;
        for (int i = 0; i < temp.getRowCount(); i++) {
            total += soloNumeros((String) contenedorPrestaciones.getValueAt(i, 5));
        }
        this.campoTotal.setText(darFormatoDinero(Integer.toString(total)));
    }

    public void agregarFila() {
        DefaultTableModel temp = (DefaultTableModel) contenedorPrestaciones.getModel();
        Object nuevo[] = {"", "", "", "", "", ""};
        temp.addRow(nuevo);
    }

    private void modificarProg(service.ProgramaDipreca sp) {
        sp.setCmcPaciente(this.cmc.getNumeros().getText());
        sp.setDiagnostico(this.campoDiagnosticoProfesional.getText());
        sp.setFechaDesde(retornarDesde());
        sp.setFechaHasta(retornarHasta());
        sp.setHistoriaNumeo(this.HistoriaClinica.getNumeros().getText());
        sp.setNDias(this.campoNumeroDias.getNumeros().getText());
        sp.setNombreEstablecimiento((String) this.campoEstablecimiento.getSelectedItem());
        sp.setNumeroComplementario(this.campoNumeroProgramaComplementario.getNumeros().getText());
        sp.setRutPaciente(this.campoRutPaciente.getRut().getText());
        sp.setRutProfesional(this.campoRutProfesional.getRut().getText());
        sp.setRutProfesionalExterno(this.campoRutProfesionalExterno.getRut().getText());
        sp.setRutProfesional(campoRutProfesional.getRut().getText());
        sp.setValorTotal(this.campoTotal.getText());
        editarProgramaDipreca(sp);
    }

    public void ocultarCampos() {
        this.jLabel49.setVisible(false);
        this.campoCodigo.setVisible(false);
        this.jLabel69.setVisible(false);
        this.jLabel55.setVisible(false);
        this.jLabel51.setVisible(false);
        this.campoCantidad.setVisible(false);
        this.jLabel56.setVisible(false);
        this.jLabel53.setVisible(false);
        this.campoPrestacion.setVisible(false);
        this.jLabel60.setVisible(false);
        this.campoPrecio.setVisible(false);
        this.jLabel58.setVisible(false);
        this.jLabel61.setVisible(false);
        this.campoTotal1.setVisible(false);
        this.jLabel10.setVisible(false);
        this.jLabel31.setVisible(false);
        this.jLabel36.setVisible(false);
        this.jLabel26.setVisible(false);
        this.jLabel38.setVisible(false);
        this.mensajeriaInformacion1.setVisible(false);
        this.campoMensajeria.setVisible(false);
        this.jLabel47.setVisible(false);
        this.jLabel55.setVisible(false);
        this.jLabel56.setVisible(false);
        this.jLabel58.setVisible(false);
    }

    public void mostrarCampos() {
        this.jLabel49.setVisible(true);
        this.campoCodigo.setVisible(true);
        this.jLabel69.setVisible(true);
        this.jLabel55.setVisible(true);
        this.jLabel51.setVisible(true);
        this.campoCantidad.setVisible(true);
        this.jLabel56.setVisible(true);
        this.jLabel53.setVisible(true);
        this.campoPrestacion.setVisible(true);
        this.jLabel60.setVisible(true);
        this.campoPrecio.setVisible(true);
        this.jLabel58.setVisible(true);
        this.jLabel61.setVisible(true);
        this.campoTotal1.setVisible(true);
        this.jLabel10.setVisible(true);
        this.jLabel31.setVisible(true);
        this.jLabel36.setVisible(true);
        this.jLabel26.setVisible(true);
        this.jLabel38.setVisible(true);
        this.mensajeriaInformacion1.setVisible(true);
        this.campoMensajeria.setVisible(true);
        this.jLabel47.setVisible(true);
        this.jLabel55.setVisible(true);
        this.jLabel56.setVisible(true);
        this.jLabel58.setVisible(true);
    }

    private void calcularCantidadSesiones(service.ProgramaDipreca sp) {
        int max = 0;
        for (int i = 0; i < contenedorPrestaciones.getRowCount(); i++) {
            int value = Integer.parseInt((String) contenedorPrestaciones.getValueAt(i, 2));
            if (value > max) {
                max = value;
            }
        }
        System.out.println("cantidad de citas " + max);
        sp.setCantidadCitas(max);
        sp.setCantidadCitasTotal(max);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JDialog DialogoVer;
    private javax.swing.JLabel EtiquetaApellidoPaternoPaciente;
    private componentes.Numeros HistoriaClinica;
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonAgregarPrestacion;
    private javax.swing.JButton botonCancel;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonEliminarPrestacion;
    private javax.swing.JButton botonImprimir;
    private javax.swing.JTextField campoApellidoMaternoPaciente;
    private javax.swing.JTextField campoApellidoPaternoPaciente;
    private componentes.Numeros campoCantidad;
    private javax.swing.JComboBox campoCodigo;
    private javax.swing.JTextField campoDiagnosticoProfesional;
    private javax.swing.JTextField campoEdadPaciente;
    private javax.swing.JComboBox campoEstablecimiento;
    private com.toedter.calendar.JDateChooser campoFechaDesde;
    private com.toedter.calendar.JDateChooser campoFechaHasta;
    private javax.swing.JLabel campoMensajeria;
    private javax.swing.JTextField campoNombreEstablecimientoExterno;
    private javax.swing.JTextField campoNombreExterno;
    private javax.swing.JTextField campoNombreProfesional;
    private javax.swing.JTextField campoNombresPaciente;
    private componentes.Numeros campoNumeroDias;
    public componentes.Numeros campoNumeroPrograma;
    private componentes.Numeros campoNumeroProgramaComplementario;
    private componentes.Dinero campoPrecio;
    private javax.swing.JTextField campoPrestacion;
    private componentes.Rut campoRutPaciente;
    private componentes.Rut campoRutProfesional;
    private componentes.Rut campoRutProfesionalExterno;
    private javax.swing.JTextField campoSexoPaciente;
    private javax.swing.JTextField campoTotal;
    private javax.swing.JTextField campoTotal1;
    private javax.swing.JTextField celularExterno;
    private javax.swing.JTextField celularPaciente;
    private javax.swing.JTextField celularProfesional;
    private componentes.Numeros cmc;
    private javax.swing.JLabel contenedorFonasa;
    public javax.swing.JTable contenedorPrestaciones;
    private javax.swing.JTextField especialidad;
    private javax.swing.JLabel etiquetaApellidoMaternoPaciente;
    private javax.swing.JLabel etiquetaCMC;
    private javax.swing.JLabel etiquetaCalle;
    private javax.swing.JLabel etiquetaCelularExterno;
    private javax.swing.JLabel etiquetaCelularPaciente;
    private javax.swing.JLabel etiquetaCiudad;
    private javax.swing.JLabel etiquetaComuna;
    private javax.swing.JLabel etiquetaDiagnostico1;
    private javax.swing.JLabel etiquetaEdad;
    private javax.swing.JLabel etiquetaEspecialidadExterno;
    private javax.swing.JLabel etiquetaFechaDesde;
    private javax.swing.JLabel etiquetaFechaHasta;
    private javax.swing.JLabel etiquetaHistoriaClinica;
    private javax.swing.JLabel etiquetaNombreEstablecimiento;
    private javax.swing.JLabel etiquetaNombreProfesional;
    private javax.swing.JLabel etiquetaNombreProfesionalExterno;
    private javax.swing.JLabel etiquetaNombresPaciente;
    private javax.swing.JLabel etiquetaNumero;
    private javax.swing.JLabel etiquetaNumeroComplementario;
    private javax.swing.JLabel etiquetaNumeroDias;
    private javax.swing.JLabel etiquetaNumeroPrograma;
    private javax.swing.JLabel etiquetaPoblacion;
    private javax.swing.JLabel etiquetaRutPaciente;
    private javax.swing.JLabel etiquetaRutProfesional;
    private javax.swing.JLabel etiquetaRutProfesionalExterno;
    private javax.swing.JLabel etiquetaSexo;
    private javax.swing.JLabel etiquetaTelefonoExterno;
    private javax.swing.JLabel etiquetaTelefonoPaciente;
    private javax.swing.JLabel etiquetaTotal;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel102;
    private javax.swing.JLabel jLabel103;
    private javax.swing.JLabel jLabel107;
    private javax.swing.JLabel jLabel108;
    private javax.swing.JLabel jLabel109;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel110;
    private javax.swing.JLabel jLabel113;
    private javax.swing.JLabel jLabel114;
    private javax.swing.JLabel jLabel116;
    private javax.swing.JLabel jLabel117;
    private javax.swing.JLabel jLabel118;
    private javax.swing.JLabel jLabel119;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel120;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JLabel jLabel52;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JLabel jLabel59;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel60;
    private javax.swing.JLabel jLabel61;
    private javax.swing.JLabel jLabel67;
    private javax.swing.JLabel jLabel69;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel71;
    private javax.swing.JLabel jLabel73;
    private javax.swing.JLabel jLabel74;
    private javax.swing.JLabel jLabel80;
    private javax.swing.JLabel jLabel82;
    private javax.swing.JLabel jLabel84;
    private javax.swing.JLabel jLabel87;
    private javax.swing.JLabel jLabel88;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    public javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator10;
    private javax.swing.JSeparator jSeparator11;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JSeparator jSeparator13;
    private javax.swing.JSeparator jSeparator14;
    private javax.swing.JSeparator jSeparator15;
    private javax.swing.JSeparator jSeparator16;
    private javax.swing.JSeparator jSeparator17;
    private javax.swing.JSeparator jSeparator19;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator20;
    private javax.swing.JSeparator jSeparator21;
    private javax.swing.JSeparator jSeparator22;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JLabel mensajeriaInformacion1;
    public javax.swing.JTable tablaContenedoraPrestaciones;
    private javax.swing.JTextField telefonoExterno;
    private javax.swing.JTextField telefonoPaciente;
    private javax.swing.JTextField telefonoProfesional;
    // End of variables declaration//GEN-END:variables

    public void limpiarCamposPrestacion() {
        this.campoCantidad.getNumeros().setText("");
        this.campoCodigo.setSelectedIndex(0);
        this.campoCantidad.getNumeros().setText("");
        this.campoPrestacion.setText("");
        String cod = (String) campoCodigo.getSelectedItem();
        service.CodigosPrestaciones c = (service.CodigosPrestaciones) cargarCodigoPrestacion(cod);
        if (c != null) {
            campoPrestacion.setText(c.getNombrePrestacion());
        }


    }

    public boolean camposObligatoriosLlenosPrestacion() {
        if (!campoPrecio.getDinero().getText().equals("")
                && !campoCantidad.getNumeros().getText().equals("")
                && !((String) campoCodigo.getSelectedItem()).equals("Seleccionar")) {
            return true;
        }
        return false;
    }

    public void cargarCodigos() {
        campoCodigo.removeAllItems();
        List<service.CodigosPrestaciones> codigos = listarCodigosPrestaciones();
        for (service.CodigosPrestaciones c : codigos) {
            campoCodigo.addItem(c.getId());
        }
    }

    public void cargarEstablecimiento() {
        campoEstablecimiento.removeAllItems();
        campoEstablecimiento.addItem("Ninguno");
        List<service.Establecimiento> establecimientos = listarEstablecimientos();
        for (service.Establecimiento e : establecimientos) {
            campoEstablecimiento.addItem(e.getNombre());
        }
    }

    public void campoDineroFocusLost() {
        this.campoPrecio.getDinero().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (!campoPrecio.getDinero().getText().equals("") && !campoCantidad.getNumeros().getText().equals("")) {
                    // calculo precio para total
                    campoTotal1.setText(retornarDinero(Integer.toString(soloNumeros(campoPrecio.getDinero().getText()) * campoCantidad.getNumero())));
                } else {
                    campoTotal1.setText("");
                }
            }
        });
    }

    public void campoCantidadFocusLost() {
        this.campoCantidad.getNumeros().addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (!campoPrecio.getDinero().getText().equals("") && !campoCantidad.getNumeros().getText().equals("")) {
                    // calculo precio para total
                    campoTotal1.setText(retornarDinero(Integer.toString(soloNumeros(campoPrecio.getDinero().getText()) * campoCantidad.getNumero())));
                } else {
                    campoTotal1.setText("");
                }
            }
        });
    }

    private static Object cargarPaciente(java.lang.String rut) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();
        return port.cargarPaciente(rut);
    }

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }

    private static Object cargarUsuario(java.lang.String rut) {
        service.UsuarioWSService service = new service.UsuarioWSService();
        service.UsuarioWS port = service.getUsuarioWSPort();
        return port.cargarUsuario(rut);
    }

    @Override
    public int print(Graphics grphcs, PageFormat pf, int i) throws PrinterException {
        if (i > 0) { /* We have only one page, and 'page' is zero-based */
            return NO_SUCH_PAGE;
        }
        Graphics2D g2d = (Graphics2D) grphcs;
        g2d.translate(pf.getImageableX(), pf.getImageableY());
        g2d.scale(0.7, 0.7);

        return PAGE_EXISTS;
    }

    private boolean validarNumeroDeProgramaDipreca() {
        List<service.ProgramaDipreca> list = listarProgramasDipreca();
        for (service.ProgramaDipreca p : list) {
            if (Integer.parseInt(p.getNumeroPrograma()) == campoNumeroPrograma.getNumero()) {
                return false;
            }
        }
        return true;
    }

    private static Object cargarPrivilegios(java.lang.String rut) {
        service.PrivilegiosWS_Service service = new service.PrivilegiosWS_Service();
        service.PrivilegiosWS port = service.getPrivilegiosWSPort();
        return port.cargarPrivilegios(rut);
    }

    private static boolean agregarProgramaDipreca(service.ProgramaDipreca programaDipreca) {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.agregarProgramaDipreca(programaDipreca);
    }

    private static boolean editarProgramaDipreca(service.ProgramaDipreca programaDipreca) {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.editarProgramaDipreca(programaDipreca);
    }

    private static java.util.List<service.ProgramaDipreca> listarProgramasDipreca() {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.listarProgramasDipreca();
    }

    private static Object obtenerProgramaDipreca(java.lang.String numero) {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.obtenerProgramaDipreca(numero);
    }

    private static Object cargarProfesionalExterno(java.lang.String rut) {
        service.ProfesionalExternoWSService service = new service.ProfesionalExternoWSService();
        service.ProfesionalExternoWS port = service.getProfesionalExternoWSPort();
        return port.cargarProfesionalExterno(rut);
    }

    private static Object cargarCodigoPrestacion(java.lang.String id) {
        service.PrestacionMedicaGeneralWSService service = new service.PrestacionMedicaGeneralWSService();
        service.PrestacionMedicaGeneralWS port = service.getPrestacionMedicaGeneralWSPort();
        return port.cargarCodigoPrestacion(id);
    }

    private static java.util.List<service.PrestacionMedica> listarPrestacionesMedicasGeneral() {
        service.PrestacionMedicaGeneralWSService service = new service.PrestacionMedicaGeneralWSService();
        service.PrestacionMedicaGeneralWS port = service.getPrestacionMedicaGeneralWSPort();
        return port.listarPrestacionesMedicasGeneral();
    }

    private static boolean agregarPrestacionMedicaGeneral(service.PrestacionMedica prestacion) {
        service.PrestacionMedicaGeneralWSService service = new service.PrestacionMedicaGeneralWSService();
        service.PrestacionMedicaGeneralWS port = service.getPrestacionMedicaGeneralWSPort();
        return port.agregarPrestacionMedicaGeneral(prestacion);
    }

    private static boolean eliminarPrestacionMedicaGeneral(java.lang.Long id) {
        service.PrestacionMedicaGeneralWSService service = new service.PrestacionMedicaGeneralWSService();
        service.PrestacionMedicaGeneralWS port = service.getPrestacionMedicaGeneralWSPort();
        return port.eliminarPrestacionMedicaGeneral(id);
    }

    private static java.util.List<service.CodigosPrestaciones> listarCodigosPrestaciones() {
        service.PrestacionMedicaGeneralWSService service = new service.PrestacionMedicaGeneralWSService();
        service.PrestacionMedicaGeneralWS port = service.getPrestacionMedicaGeneralWSPort();
        return port.listarCodigosPrestaciones();
    }

    private static java.util.List<service.Establecimiento> listarEstablecimientos() {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.listarEstablecimientos();
    }

    private static Object cargarPrestacionMedicaGeneral(java.lang.Long id) {
        service.PrestacionMedicaGeneralWSService service = new service.PrestacionMedicaGeneralWSService();
        service.PrestacionMedicaGeneralWS port = service.getPrestacionMedicaGeneralWSPort();
        return port.cargarPrestacionMedicaGeneral(id);
    }

    private static Object cargarProgramaFonasaPorNumero(java.lang.String id) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.cargarProgramaFonasaPorNumero(id);
    }
}
